package com.gsnd.gsnd22estore.service.impl;

import com.gsnd.gsnd22estore.dto.OrderItemsDto;
import com.gsnd.gsnd22estore.dto.QueryOrderDto;
import com.gsnd.gsnd22estore.dto.extend.QueryOrderDTOExtend;
import com.gsnd.gsnd22estore.mapper.EsOrderMapper;
import com.gsnd.gsnd22estore.service.OrderService;
import com.gsnd.gsnd22estore.utils.BeanCopyUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.concurrent.locks.Condition;


public class OrderServiceImpl implements OrderService {
/*
    @Autowired
    EsOrderMapper orderMapper;
    public List<QueryOrderDto> getOrderByUser(Integer userId, Integer status, String orderId) {
        /*List<QueryOrderDto> queryOrderDTOS = orderMapper.selectByCondition(userId, orderId, status);

        // 推荐使用数学计算
        for(QueryOrderDto o: queryOrderDTOS){
            // 准备两个变量进行接收
            int numSum = 0;
            double priceSum = 0.0;
            List<OrderItemsDto> orderItemsDTOS = orderMapper.selectItemByOrderId(o.getOrderId());
            for(OrderItemsDto oi : orderItemsDTOS){
                numSum += oi.getNum();
                priceSum += oi.getTotalPrice();
            }
            o.setTotalNum(numSum);
            o.setTotalPrice(priceSum);
        }
        System.out.println(queryOrderDTOS);
        return queryOrderDTOS;
    }

    @Override
    public QueryOrderDTOExtend getOrderDetailByUser(Integer userId, String orderId) {
        List<QueryOrderDto> queryOrderDTOS = orderMapper.selectByCondition(userId, orderId, null);
        // 取出查询的订单对象
        QueryOrderDto queryOrderDTO = queryOrderDTOS.get(0);
        // 复制bean对象
        QueryOrderDTOExtend oe = BeanCopyUtils.copyBean(queryOrderDTO, QueryOrderDTOExtend.class);
        // 根据oe查询订单项
        List<OrderItemsDto> orderItemsDTOS = orderMapper.selectItemByOrderId(oe.getOrderId());
        oe.setOrderItems(orderItemsDTOS);

        return oe;
    }*/

}
